package com.intelij.adapter.util;

import com.intellij.diagram.DiagramFileEditor;
import com.intellij.diagram.presentation.DiagramState;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorStateLevel;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.uml.UmlVirtualFileSystem;

public class UmlSupportUtils {

    public static DiagramState getDiagramStateByEvent(AnActionEvent event) {
        FileEditor fileEditor = event.getData(PlatformDataKeys.FILE_EDITOR);
        DiagramFileEditor dfEditor = (DiagramFileEditor) fileEditor;
        return  (DiagramState) dfEditor.getState(FileEditorStateLevel.FULL);
    }


    public static UmlVirtualFileSystem.UmlVirtualFile getUmlVirtualFileByEvent(AnActionEvent event) {
        PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE);
        VirtualFile virtualFile = psiFile.getVirtualFile();
        return (UmlVirtualFileSystem.UmlVirtualFile) virtualFile;
    }


    public static boolean isUmlSupport(AnActionEvent event) {
        PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE);
        VirtualFile virtualFile = psiFile.getVirtualFile();
        boolean isSmlSupport = false;
        if (virtualFile instanceof UmlVirtualFileSystem.UmlVirtualFile) {
            isSmlSupport = true;
        }
        return isSmlSupport;
    }
}
